﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class GameOverUI : MonoBehaviour
{
    public Text TxtGameOver;
    public float TimeToShow;
    public string SceneName;
    public GameObject ObjSprite;
    public Text TextScore;
    private float m_fTimeToShow;
    private bool m_bStart;
    private bool m_bOver;
    private int m_nScore;
    // Start is called before the first frame update
    void Start()
    {
        
    }
    public void AddScore()
    {
        m_nScore++;
        TextScore.text = string.Format("Score: {0}", m_nScore);
    }

    // Update is called once per frame
    void Update()
    {
        if(m_bStart == true)
        {
            m_fTimeToShow += Time.deltaTime;
            if(m_fTimeToShow >= TimeToShow)
            {
                m_bStart = false;
                m_bOver = true;
                ObjSprite.SetActive(true);
            }
            TxtGameOver.color = new Color(TxtGameOver.color.r, TxtGameOver.color.g, TxtGameOver.color.b, m_fTimeToShow / TimeToShow);
        }
        if(m_bOver == true)
        {
            if( Input.anyKeyDown )
            {
                SceneManager.LoadScene(SceneName);
            }
        }
    }
    public void GameOver()
    {
        m_bStart = true;
    }
}
